package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.RoleDto;
import com.zzyl.service.RoleService;
import com.zzyl.vo.RoleVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;


    @PostMapping("/page//{pageNum}/{pageSize}")
    @ApiOperation("角色管理分页展示")
    public ResponseResult<PageResponse<RoleVo>> queryPage(@RequestBody RoleDto roleDto, @PathVariable Integer pageSize, @PathVariable Integer pageNum) {
        PageResponse<RoleVo> roleVoPageResponse = roleService.queryPage(roleDto, pageNum, pageSize);
        return success(roleVoPageResponse);
    }

    @PutMapping()
    @ApiOperation("角色管理新增")
    public ResponseResult insert(@RequestBody RoleDto roleDto) {
        roleService.insert(roleDto);
        return success();
    }

    @GetMapping("/find-checked-resources/{roleId}")
    @ApiOperation("角色管理新增")
    public ResponseResult findCheckedResourcesByRoleId(@PathVariable Long roleId) {
        List<String> list = roleService.findCheckedResourcesByRoleId(roleId);
        return success(list);
    }

    @PatchMapping()
    @ApiOperation("角色、权限编辑")
    public ResponseResult editAndStatusAndResource(@RequestBody RoleDto roleDto) {
        roleService.editAndStatusAndResource(roleDto);
        return success();
    }
}
